// 引入静态路由
import { constantRoutes, asyncRoutes } from '@/router'

const state = {
    routes: constantRoutes
}

const mutations = {
    // newRoutes 是新用户登录之后获取的新路由
    setRoutes(state, newRoutes) {
        state.routes = [...constantRoutes, ...newRoutes]
        
    }
}

const actions = {
    // 筛选路由模块 menus是用户资料的标识，代表权限
    filterRoutes(context, menus) {
        var routes = []
        menus.forEach(item => {

          routes.push(...asyncRoutes.filter(route => route.name === item))
        })

        context.commit('setRoutes', routes)
        
        return routes
    }
}


export default {
    namespaced:true,
    state,
    mutations,
    actions
}